package com.huqing.icu.base.redis.utils;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.JedisPool;

import java.io.IOException;

/**
 * @Description Redis工具类
 * @Author huqing
 * @Date 2025/1/6 10:40
 **/
public class RedisUtils {

    public static Jedis getRedis(JedisPool pool) {
        if (pool != null)
            return pool.getResource();

        return null;
    }

    /**
     * close the connection
     *
     * @param jedis
     */
    public static void closeRedis(Jedis jedis) {
        if (jedis != null)
            jedis.close();
    }

    /**
     * destroy the pool
     *
     * @param pool
     */
    public static void closeRedisPool(JedisPool pool) {
        if (pool != null)
            pool.destroy();
    }

    /**
     * destroy the jedis cluster
     *
     * @param cluster
     */
    public static void closeRedisCluster(JedisCluster cluster) {
        if (cluster != null) {
            try {
                cluster.close();
            } catch (IOException e) {
                //e.printStackTrace();
            }
        }
    }
}
